package com.hnkywl.sts.dao.kcgl;

import com.hnkywl.sts.entity.xsgl.Lldmx;
import net.ruixin.orm.hibernate.SimpleHibernateTemplate;
import org.hibernate.Criteria;
import org.hibernate.criterion.CriteriaSpecification;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;


/**
 * Created with IntelliJ IDEA.
 * User: jerry
 * Date: 13-4-15
 * Time: 下午2:14
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class LldmxDao extends SimpleHibernateTemplate<Lldmx, Long> {
    public List<Map> findLldmxList(Long lldId) {
        Criteria criteria = getSession().createCriteria(Lldmx.class)
                .createAlias("kh", "kh", CriteriaSpecification.LEFT_JOIN)
                .createAlias("lld", "lld", CriteriaSpecification.LEFT_JOIN)
                .createAlias("kh.jtwz", "jtwz", CriteriaSpecification.LEFT_JOIN)
                .setProjection(Projections.projectionList()
                        .add(Property.forName("id").as("id"))
                        .add(Property.forName("kh.id").as("kh.id"))
                        .add(Property.forName("lld.lldh").as("lld.lldh"))
                        .add(Property.forName("jtwz.id").as("jtwz.id"))
                        .add(Property.forName("jtwz.oldcode").as("jtwz.oldcode"))
                        .add(Property.forName("jtwz.code").as("jtwz.code"))
                        .add(Property.forName("jtwz.name").as("jtwz.name"))
                        .add(Property.forName("jtwz.cz").as("jtwz.cz"))
                        .add(Property.forName("jtwz.dw").as("jtwz.dw"))
                        .add(Property.forName("jtwz.th").as("jtwz.th"))
                        .add(Property.forName("jtwz.ggxh").as("jtwz.ggxh"))
                        .add(Property.forName("kdsl").as("kdsl"))
                        .add(Property.forName("kddj").as("kddj"))
                        .add(Property.forName("flje").as("flje"))
                        .add(Property.forName("flsl").as("flsl"))
                        .add(Property.forName("llbz").as("llbz"))
                        .add(Property.forName("flje").as("flje"))
                ).add(Restrictions.eq("lld.id", lldId)).addOrder(Property.forName("jtwz.oldcode").asc())
                .setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
        return (List<Map>) criteria.list();
    }
}


